package com.tbb.app.base.vo;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tbb.app.base.entity.Note;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Date;
import java.util.List;

@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "笔记VO")
public class NoteVO {

    @ApiModelProperty("id")
    private String id;

    @ApiModelProperty("频道id")
    private String channelId;

    @ApiModelProperty("发布时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @ApiModelProperty("标题")
    private String title;

    @ApiModelProperty("正文")
    private String text;

    @ApiModelProperty("图片urls")
    private List<String> imgs;

    @ApiModelProperty("点赞数")
    private Integer likeNum;

    @ApiModelProperty("收藏数")
    private Integer collectNum;

    @ApiModelProperty("评论数")
    private Integer remarkNum;

    @ApiModelProperty("作者id")
    private String userId;

    @ApiModelProperty("作者昵称")
    private String userName;

    @ApiModelProperty("作者账号")
    private String userAccount;

    @ApiModelProperty("作者头像")
    private String userImg;

    @ApiModelProperty("是否已点赞")
    private Boolean isLiked;

    @ApiModelProperty("是否已关注作者，仅详情时返回值")
    private Boolean isFollowed;

    @ApiModelProperty("是否已收藏，仅详情时返回值")
    private Boolean isCollected;

    @ApiModelProperty("热度，仅查询热门笔记时返回值")
    private Integer heat;

    public NoteVO(Note n) {
        this.id = n.getId();
        this.createTime = n.getUpdateTime();
        this.title = n.getTitle();
        this.text = n.getText();
        this.imgs = JSON.parseArray(n.getImgs(), String.class);
        this.likeNum = n.getLikeNum();
        this.collectNum = n.getCollectNum();
        this.remarkNum = n.getRemarkNum();
        this.userId = n.getUserId();
        this.channelId = n.getChannelId();
    }
}
